package ym.ecrm.web.action.systemManagement;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import ym.ecrm.core.common.util.Book;
import ym.ecrm.core.common.util.ExportExcel;
import ym.ecrm.web.action.base.BaseAction;

/**
 * 
 * @author Princess
 * 
 */
public class ExportExcelAction extends BaseAction {

	// @Autowired
	// private ISystemService systemService;

	public String execute() {
		int a = 10;
		a--;
		return proccess();
	}

	public InputStream getTargetFile() throws Exception {
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		// 测试图书
		ExportExcel<Book> ex = new ExportExcel<Book>();
		String[] headers = { "图书编号", "图书名称", "图书作者", "图书价格", "图书ISBN", "图书出版社",
				"封面图片" };
		List<Book> dataset = new ArrayList<Book>();
		dataset.add(new Book(1, "jsp", "leno", 300.33f, "1234567", "清华出版社",
				null));
		dataset.add(new Book(2, "java编程思想", "brucl", 300.33f, "1234567",
				"阳光出版社", null));
		dataset.add(new Book(3, "DOM艺术", "lenotang", 300.33f, "1234567",
				"清华出版社", null));
		dataset.add(new Book(4, "c++经典", "leno", 400.33f, "1234567", "清华出版社",
				null));
		dataset.add(new Book(5, "c#入门", "leno", 300.33f, "1234567", "汤春秀出版社",
				null));
		ex.exportExcel(headers, dataset, out);
		out.flush();
		out.close();
//		System.out.println("excel导出成功！");
//		FileInputStream fin = new FileInputStream(file);
		return new ByteArrayInputStream(out.toByteArray());
	}

	public String getErrorMessage() {
		return errorMessage;
	}

	public String getSuccess() {
		return success;
	}

}
